﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Commons.CommonHelper;

namespace BuildingForm
{
    
    public partial class AllScreens : Form, IModuleExtension 
    {
        public static string strStatic;
        public AllScreens()
        {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.None;
        }

        /// <summary>
        /// esc事件
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="keyData"></param>
        /// <returns></returns>
        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            int WM_KEYDOWN = 256;
            int WM_SYSKEYDOWN = 260;
            if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
            {
                switch (keyData)
                {
                    case Keys.Escape:
                        //this.Location = new System.Drawing.Point(500, 500);
                        strStatic = null;
                        this.Close();
                        //this.FormBorderStyle = FormBorderStyle.FixedSingle;
                        //this.WindowState = FormWindowState.Normal;
                        break;
                }
            }
            return false;
        }

        /// <summary>
        /// 调用窗口
        /// </summary>
        /// <param name="title">窗体名称</param>
        /// <param name="xmmc">项目名称</param>
        /// <returns></returns>
        public bool ShowExtension(string title, string xmmc)
        {
            try
            {
                if (!string.IsNullOrEmpty(strStatic))
                {
                    return false;
                }
                strStatic = "BuildingForm";
                this.Controls.Clear();
                int totalWidth = 0;
                int count = System.Windows.Forms.Screen.AllScreens.Length;
                for (int i = 1; i < count; i++)
                {
                    string jsdm = string.Empty;
                    int num = i + 1;
                    if (System.Configuration.ConfigurationManager.AppSettings["ScreenForm"+num+""] != null)
                    {
                        jsdm = System.Configuration.ConfigurationManager.AppSettings["ScreenForm" + num + ""].ToString();
                    }
                    int width = Screen.AllScreens[i].Bounds.Width;
                    int height = Screen.AllScreens[i].Bounds.Height;
                    totalWidth += width;
                    SplitScreenStatisticsForm f = new SplitScreenStatisticsForm(jsdm);
                    f.TopLevel = false;
                    f.FormBorderStyle = FormBorderStyle.None;
                    f.Height = height;
                    f.Width = width;
                    f.Top = 0;
                    f.Left = totalWidth - width;
                    this.Controls.Add(f);
                    f.Show();
                }
                ////if (count > 0)
                ////{
                ////    int width = Screen.AllScreens[0].Bounds.Width;
                ////    int height = Screen.AllScreens[0].Bounds.Height;
                ////    totalWidth += width;
                ////    SplitScreenStatisticsForm f = new SplitScreenStatisticsForm();
                ////    f.TopLevel = false;
                ////    f.FormBorderStyle = FormBorderStyle.None;
                ////    f.Height = height;
                ////    f.Width = width;
                ////    f.Top = 0;
                ////    f.Left = totalWidth - width;
                ////    this.Controls.Add(f);
                ////    f.Show();
                ////}
                //if (count >1)
                //{
                //    int width = Screen.AllScreens[1].Bounds.Width;
                //    int height = Screen.AllScreens[1].Bounds.Height;
                //    totalWidth += width;
                //    SplitScreenStatisticsForm2 f = new SplitScreenStatisticsForm2();
                //    f.TopLevel = false;
                //    f.FormBorderStyle = FormBorderStyle.None;
                //    f.Height = height;
                //    f.Width = width;
                //    f.Top = 0;
                //    f.Left = totalWidth - width;
                //    this.Controls.Add(f); 
                //    f.Show();
                //}
                //if (count >2)
                //{
                //    int width = Screen.AllScreens[2].Bounds.Width;
                //    int height = Screen.AllScreens[2].Bounds.Height;
                //    totalWidth += width;
                //    SplitScreenStatisticsForm3 f = new SplitScreenStatisticsForm3();
                //    f.TopLevel = false;
                //    f.FormBorderStyle = FormBorderStyle.None;
                //    f.Height = height;
                //    f.Width = width;
                //    f.Top = 0;
                //    f.Left = totalWidth - width;
                //    this.Controls.Add(f);
                //    f.Show();
                //}
                //if (count > 3)
                //{
                //    int width = Screen.AllScreens[3].Bounds.Width;
                //    int height = Screen.AllScreens[3].Bounds.Height;
                //    totalWidth += width;
                //    SplitScreenStatisticsForm4 f = new SplitScreenStatisticsForm4();
                //    f.TopLevel = false;
                //    f.FormBorderStyle = FormBorderStyle.None;
                //    f.Height = height;
                //    f.Width = width;
                //    f.Top = 0;
                //    f.Left = totalWidth - width;
                //    this.Controls.Add(f);
                //    f.Show();
                //}
                //if (count > 4)
                //{
                //    int width = Screen.AllScreens[4].Bounds.Width;
                //    int height = Screen.AllScreens[4].Bounds.Height;
                //    totalWidth += width;
                //    SplitScreenStatisticsForm5 f = new SplitScreenStatisticsForm5();
                //    f.TopLevel = false;
                //    f.FormBorderStyle = FormBorderStyle.None;
                //    f.Height = height;
                //    f.Width = width;
                //    f.Top = 0;
                //    f.Left = totalWidth - width;
                //    this.Controls.Add(f);
                //    f.Show();
                //}
                this.Width = totalWidth;
                this.Height = Screen.AllScreens[0].Bounds.Height;
                this.Show();
                //this.FormBorderStyle = FormBorderStyle.None;
                //this.Dock = DockStyle.Fill;
                this.Top = 0;
                
                this.Left = Screen.AllScreens[0].Bounds.Width;
                //this.Left = 0;
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("加载失败！");
                //MessageBox.Show(ex.Message);
                return false;
            }
        }

        private void AllScreens_DoubleClick(object sender, EventArgs e)
        {
            //esc(); 
        }

        /// <summary>
        /// 退出全屏
        /// </summary>
        private void esc()
        {
            if (this.WindowState == FormWindowState.Maximized)
            {
                this.FormBorderStyle = FormBorderStyle.FixedSingle;
                this.WindowState = FormWindowState.Normal;
            }
            else
            {
                this.FormBorderStyle = FormBorderStyle.None;
                this.WindowState = FormWindowState.Maximized;
            }
        }
    }
}
